<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>数组的解构赋值</title>
</head>
<body>
  <script>
    /*
    * 基本用法
    * 1.ES6 允许按照一定的模式，从数组和对象中提取值，对变量进行赋值，这称之为解构
    */

    // es5
    // let a = 1, b=2,c=3
    // es6
    // let [a,b,c] = [1,2,3]
    // console.log(a,b,c)
    // // 嵌套数组解构
    // let [foo, [bar,[baz]]] = [1,[2,[3]]]
    // console.log(foo, bar, baz)//1,2,3
    // let [,, third] = [1,2,3]
    // console.log(third)//3
    // let [x,,y] = [1,2,3]
    // console.log(x,y)//1,3
    // let [head,...tail] = [1,2,3,4]
    // console.log(head,tail)//1,[2,3,4]

    // let [test] = []
    // console.log(test) //undefined

    /*
    * 默认值
    * 1.解构赋值允许默认值
    * 2. 默认值内部严格使用相等运算符(===)，来判断一个位置是否有值，只有当一个数组成员严格等于undefined，默认值才会生效
    * 
    */
    let [foo=true] = []
    console.log(foo) //true

    let [x=1] = [undefined]
    console.log(x) //undefined
    let [y=1] = [null]
    console.log(y) //null
  </script>
</body>
</html>